<?php
error_reporting(1);
$target = '/data/wwwroot/zone'; // 生产环境web目录
//$target = '/var/www/zone'; // 生产环境web目录
$token = 'asas';
$wwwUser = 'www';
$wwwGroup = 'www';
//$json = json_decode(file_get_contents('php://input'), true);
//if (empty($json['token']) || $json['token'] !== $token) {
//    exit('error request');
//}
//$repo = $json['repository']['name'];
 $cmds = array(
     "cd $target && git pull",
     "chown -R {$wwwUser}:{$wwwGroup} $target/",
 );
 foreach ($cmds as $cmd) {
     shell_exec($cmd);
 }
// 感谢@墨迹凡指正，可以直接用www用户拉取代码而不用每次拉取后再修改用户组
//
//$cmd = "sudo -Hu www-data cd $target && git pull";
//
//shell_exec($cmd);